package com.levy.contronller.javaWeb.findImageTest;

import cn.hutool.core.io.FileUtil;
import org.junit.Test;

import java.util.List;

public class ImgCmpUtilTest {
    @Test
    public void testa() {
        //原图片
        String tSrcImgPath = "G:/login1.png";
        //有标记框的图片
        String tLabelImgPath = "G:/login2.png";
        //标记框颜色
        int tLabelColor = -1237980; //红色
        Boolean tExist = new ImgCmpUtil().isLabelPatchExist(tSrcImgPath, tLabelImgPath, tLabelColor);

        System.out.println("tExist=" + tExist);
    }

    @Test
    public void testb() {
        //原图片
        String tSrcImgPath = "G:/src.png";
        //有标记框的图片
        String tLabelImgPath = "G:/copy1.png";

        String dir = "G://pdf/small/";
        String findTitle1 = "G:\\pdf\\find\\find_title_1.png";
        String findTitle2 = "G:\\pdf\\find\\find_title_2.png";
        String fileNameTitle1 = "";
        String fileNameTitle2 = "";

        List<String> fileNames = FileUtil.listFileNames(dir);
        long l = System.currentTimeMillis();
        for (String s : fileNames) {
            String srcPath = dir + s;
            System.out.println(srcPath);

            Boolean tExist1 = new ImgCmpUtil().isPatchExist(srcPath, findTitle1);
            if (tExist1) {
                //找到第一个图表，记录文件名
                fileNameTitle1 = s;
                System.out.println(fileNameTitle1);
            }

            boolean tExist2 = new ImgCmpUtil().isPatchExist(srcPath, findTitle2);
            if (tExist2) {
                //找到第二个图表
                fileNameTitle2 = s;
                System.out.println(fileNameTitle2);
                break;
            }
        }

        System.out.println((System.currentTimeMillis()-l)/1000);
        System.out.println(fileNameTitle1);
        System.out.println(fileNameTitle2);
    }
}
